home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-25 | 409 b | 19 lines | [TEXT/CWIE] |
- // STL10.cp
- #include <string>
-
- int main()
- {
- std::string a = "shared string";
- std::string b(a); // a and b are sharing the same string buffer
-
- if (a[0] != b[0]) // line 1
- {
- a = b = "un" + a; // line 2
- }
- if (a.c_str()[0] == b.c_str()[0]) // line 3
- {
- a = b = "un" + a; // line 4
- }
- // a and b are no longer sharing the same string buffer
- // Question: At what line is the buffer copied?
- }